package com.qidian.buy.common.pojo;

import com.qidian.buy.common.util.Constant;

/**
 * @author 戴着假发的程序员
 * @company 起点编程
 * @date 2024/7/11 15:18
 */
public class BuyResult {
    private int code;
    private String msg;
    private Object data;

    // 通过静态方法快速生成次类对象
    public static BuyResult success(){
        return new BuyResult(Constant.RESPONSE_STATUS_OK,"OK",null);
    };
    public static BuyResult success(String msg){
        return new BuyResult(Constant.RESPONSE_STATUS_OK,msg,null);
    };
    public static BuyResult success(Object data){
        return new BuyResult(Constant.RESPONSE_STATUS_OK,"OK",data);
    };
    public static BuyResult success(String msg,Object data){
        return new BuyResult(Constant.RESPONSE_STATUS_OK,msg,data);
    };

    public static BuyResult error(){
        return new BuyResult(Constant.RESPONSE_STATUS_ERROR,"OK",null);
    };
    public static BuyResult error(String msg){
        return new BuyResult(Constant.RESPONSE_STATUS_ERROR,msg,null);
    };
    public static BuyResult error(Object data){
        return new BuyResult(Constant.RESPONSE_STATUS_ERROR,"OK",data);
    };
    public static BuyResult error(String msg,Object data){
        return new BuyResult(Constant.RESPONSE_STATUS_ERROR,msg,data);
    };

    public static BuyResult duplicate(){
        return new BuyResult(Constant.RESPONSE_STATUS_DUPLICATE,"OK",null);
    };
    public static BuyResult duplicate(String msg){
        return new BuyResult(Constant.RESPONSE_STATUS_DUPLICATE,msg,null);
    };
    public static BuyResult duplicate(Object data){
        return new BuyResult(Constant.RESPONSE_STATUS_DUPLICATE,"OK",data);
    };
    public static BuyResult duplicate(String msg,Object data){
        return new BuyResult(Constant.RESPONSE_STATUS_DUPLICATE,msg,data);
    };

    public static BuyResult isSuccess(int result){
        return result == 1 ? success() : error();
    }

    public BuyResult() {
    }

    public BuyResult(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
